// @ts-nocheck
import { createRouter, createWebHistory } from 'vue-router'
import TargetComponent from '@/views/projectManage/projectManage/index.vue'
import { userUserStore } from '@/stores'
import { getCurrentInstance } from 'vue';

const routes = [{
            path: '/login',
            // @ts-ignore
            component: () =>
                import ('@/views/Login/login.vue')
        },
        {
            path: '/',
            name: 'layout',
            component: () =>
                import ('@/views/Layout/LayoutTest.vue'),
            redirect: '/teamwork',
            children: [{
                    path: '/article/manage',
                    component: () =>
                        import ('@/views/article/articleManage/index.vue')
                },
                {
                    path: '/teamwork',
                    component: () =>
                        import ('@/views/projectManage/projectManage/teamwork/index.vue')
                },
                {
                    path: '/project/manage',
                    component: () =>
                        import ('@/views/projectManage/projectManage/index.vue'),
                    children: [{
                        path: 'mywork',
                        component: () =>
                            import ('@/views/projectManage/myWork/index.vue'),
                    }, {
                        path: 'worked',
                        component: () =>
                            import ('@/views/projectManage/myWork/worked.vue'),
                    }, {
                        path: 'created',
                        component: () =>
                            import ('@/views/projectManage/myWork/created.vue'),
                    }]
                },
                {
                    path: '/project/manage/projectCollaboration',
                    component: () =>
                        import ('@/views/projectManage/projectCollaboration/index.vue')
                },
            ]
        }
    ]
    // 创建 router 实例
const router = createRouter({
    // @ts-ignore
    history: createWebHistory(
        import.meta.env.BASE_URL),
    routes
})


// @ts-ignore
router.beforeEach((to, from, next) => {
    // @ts-ignore
    const storedToken = localStorage.getItem('token')
        // console.log('outside');
        // if (!storedToken && to.path !== '/login') {
        //   console.log('INside');
        //   next('/login')
        //   // return '/login'
        // }

    next()
})

export default router